﻿using System;
using UnityEngine;
using UnityEngine.SceneManagement;
using Utility;

namespace ViewController.UI
{
    public class UIGameOver : MonoBehaviour
    {
        private readonly Lazy<GUIStyle> _buttonStyle = new(() => new GUIStyle(GUI.skin.button)
        {
            fontSize = 40,
            alignment = TextAnchor.MiddleCenter
        });

        private readonly Lazy<GUIStyle> _labelStyle = new(() => new GUIStyle(GUI.skin.label)
        {
            fontSize = 80,
            alignment = TextAnchor.MiddleCenter
        });

        private void OnGUI()
        {
            var labelRect = RectHelper.RectForAnchorCenter(Screen.width * 0.5f, Screen.height * 0.5f, 400, 100);
            GUI.Label(labelRect, "游戏失败", _labelStyle.Value);

            var buttonRect = RectHelper.RectForAnchorCenter(Screen.width * 0.5f, Screen.height * 0.5f + 150, 200, 100);
            if (GUI.Button(buttonRect, "回到首页", _buttonStyle.Value)) SceneManager.LoadScene("GameStart");
        }
    }
}